
#include <BFile>
#include <BEntry>
#include <BFolder>
#include "member_BObject.h"
#include "member_BWidget.h"
#include "member_BStyle.h"
#include "member_BIcon.h"
#include "IGlobal.h"
#include "member_BStyleDocument.h"

using namespace BWE;

member_BStyleDocument::member_BStyleDocument(BStyleDocument* styleDocument)
{
	boss = styleDocument;
	message = new BString();
	line = 0;
	linePos = 0;
}
member_BStyleDocument::~member_BStyleDocument()
{

}

void member_BStyleDocument::read(BStyle* style, const BString& text, int& pos)
{
	BString temp;
	BString comment;
	while (pos < text.size())
	{
		if (text[pos] == '\n' && pos > linePos)
		{
			line++;
			linePos = pos;
		}
		if (text[pos] == '\r' || text[pos] == '\t' || text[pos] == '\n')
		{
			pos++;
			continue;
		}
		if (text[pos] == '/' && text(pos + 1) == '*')
		{
			readComment(text, ++pos, comment);
			continue;
		}
		if (text[pos] == '/' && text(pos + 1) == '/')
		{
			readComment(text, ++pos, comment);
			continue;
		}
		char code = text[pos];
		if (code == '}')
		{
			pos++;
			break;
		}
		if (code == ';')
		{
			readDesc(temp, style);
			temp.reset();
			pos++;
			continue;
		}
		if (code == '{')
		{
			pos++;
			BString str;
			while (temp.contain(','))
			{
				int end = temp.find(',');
				temp.substr(str, 0, end);
				temp.remove(0, end + 1);
				BStyle* child = findChild(str, style);
				int begin = pos;
				read(child, text, pos);
				pos = begin;
			}
			BStyle* child = findChild(temp, style);
			read(child, text, pos);
			temp.reset();
			continue;
		}
		temp.append(code);
		pos++;
	}
	if (temp.size() > 1)
	{
		readDesc(temp, style);
		temp.reset();
	}
	imageMap.clear();
	iconMap.clear();
}
void member_BStyleDocument::write(const BStyle* style, BString& text, int level)
{
	if (style_member(style)->valueMap.size())
	{
		for (auto it = style_member(style)->valueMap.begin(); it.valid(); ++it)
		{
			text.append('\t', level);
			assemble(text, it.key(), it.value());
			text << '\n';
		}
	}

	if (style_member(style)->colorMap.size())
	{
		BString value;
		for (auto it = style_member(style)->colorMap.begin(); it.valid(); ++it)
		{
			text.append('\t', level);
			assemble(text, it.key(), it.value());
			text << '\n';
		}
	}

	if (style_member(style)->imageMap.size())
	{
		for (auto it = style_member(style)->imageMap.begin(); it.valid(); ++it)
		{
			text.append('\t', level);
			assemble(text, it.key(), it.value());
			text << '\n';
		}
	}

	if (style_member(style)->iconMap.size())
	{
		for (auto it = style_member(style)->iconMap.begin(); it.valid(); ++it)
		{
			text.append('\t', level);
			assemble(text, it.key(), it.value());
			text << '\n';
		}
	}

	if (style_member(style)->namedFontMap.size())
	{
		for (auto it = style_member(style)->namedFontMap.begin(); it.valid(); ++it)
		{
			const BString& name = it.key();
			const BFont* font = it.value();
			text.append('\t', level);
			text << "*font" << name << ':' << font->name() << ";\n";
		}
	}
	if (style_member(style)->namedColorMap.size())
	{
		for (auto it = style_member(style)->namedColorMap.begin(); it.valid(); ++it)
		{
			const BString& name = it.key();
			const BColor& color = it.value();
			text.append('\t', level);
			text << "*color" << name << ':' << color.r() << ", " << color.g() << ", " << color.b();
			if (color.a() < 255)
				text << ", " << color.a();
			text << ";\n";
		}
	}

	if (style_member(style)->namedImageMap.size())
	{
		for (auto it = style_member(style)->namedImageMap.begin(); it.valid(); ++it)
		{
			const BString& name = it.key();
			const BImage* image = it.value();
			text.append('\t', level);
			text << "*image: " << name << ':' << image->fileName() << ";\n";
		}
	}

	if (style_member(style)->namedIconMap.size())
	{
		for (auto it = style_member(style)->namedIconMap.begin(); it.valid(); ++it)
		{
			const BString& name = it.key();
			const BIcon* icon = it.value();
			text.append('\t', level);
			text << "*icon: " << name << ':' << icon->name() << ";\n";
		}
	}

	if (style_member(style)->transMap.size())
	{
		for (auto it = style_member(style)->transMap.begin(); it.valid(); ++it)
		{
			const BString& name = it.key();
			const BString& word = it.value();
			text.append('\t', level);
			text << "*trans: " << name << ':' << word << ";\n";
		}
	}

	if (style_member(style)->subs.size())
	{
		for (int i = 0; i < style_member(style)->subs.size(); i++)
		{
			const BStyle* sub = style_member(style)->subs[i];
			text.append('\t', level);
			text << ':';
			if (!sub->heritable())
				text << '.';
			text << sub->type();
			if (sub->name().size())
				text << '#' << sub->name();
			text << "{\n";
			write(sub, text, level + 1);
			text.append('\t', level);
			text << "}\n";
		}
	}

	if (style_member(style)->children.size())
	{
		for (int i = 0; i < style_member(style)->children.size(); i++)
		{
			const BStyle* child = style_member(style)->children[i];
			text.append('\t', level);
			if (!child->heritable())
				text << '.';
			text << child->type();
			if (child->name().size())
				text << '#' << child->name();
			text << "{\n";
			write(child, text, level + 1);
			text.append('\t', level);
			text << "}\n";
		}
	}
}

bool member_BStyleDocument::readComment(const BString& text, int& pos, BString& comment)
{
	comment.reset();
	if (text[pos] == '*')
	{
		while (++pos < text.size())
		{
			char c = text[pos];
			if (c == '\n' && pos > linePos)
			{
				line++;
				linePos = pos;
			}
			else if (c == '*' && text(pos + 1) == '/')
			{
				pos += 2;
				return true;
			}
			comment << c;
		}
		return pos == text.size();
	}
	if (text[pos] == '/')
	{
		while (++pos < text.size())
		{
			char c = text[pos];
			if (c == '\n')
			{
				pos++;
				line++;
				linePos = pos;
				return true;
			}
			comment << c;
		}
		return pos == text.size();
	}
	return false;
}
BStyle* member_BStyleDocument::findChild(BString& text, BStyle* style)
{
	int end = text.find('>');
	if (end < text.size())
	{
		BString str;
		text.substr(str, 0, end);
		BStyle* child = addStyle(str, style);
		int pos = end + 1;
		while (child && pos < text.size())
		{
			end = text.find('>', pos);
			text.substr(str, pos, end);
			child = addStyle(str, child);
			pos = end + 1;
		}
		return child;
	}
	BStyle* child = addStyle(text, style);
	return child;
}
BStyle* member_BStyleDocument::addStyle(BString& text, BStyle* parent)
{
	text.simplify();
	text.trimmed();
	if (text.beginWith(':'))
	{
		BStyle* style = addSubStyle(text, 1, parent);
		return style;
	}
	int stop = text.find(':');
	BString type;
	BString name;
	int name_pos = text.find('#', 0, stop);
	text.substr(type, 0, name_pos);
	type.simplify();
	type.trimmed();
	if (name_pos < stop)
	{
		text.substr(name, name_pos + 1, stop);
		name.simplify();
		name.trimmed();
	}
	bool heritable = true;
	if (type.beginWith('.'))
	{
		type.remove(0);
		heritable = false;
	}
	BStyle* style = parent->child(type, name);
	if (style == 0)
	{
		style = new BStyle();
		object_member(style)->name = name;
		style_member(style)->type = type;
		style_member(style)->heritable = heritable;
		parent->addChild(style);
	}
	if (stop < text.size())
	{
		style = addSubStyle(text, stop + 1, style);
	}
	return style;
}
BStyle* member_BStyleDocument::addSubStyle(BString& text, int pos, BStyle* style)
{
	BString name;
	BString subHead;
	int stop = text.find(':', pos);
	text.substr(name, pos, stop);
	name.simplify();
	name.trimmed();
	BStyle* subStyle = style->sub(name);
	if (subStyle == 0)
	{
		subStyle = new BStyle();
		subStyle->setName(name);
		style->addSub(subStyle);
	}
	if (stop < text.size())
	{
		subStyle = addSubStyle(text, stop + 1, subStyle);
	}
	return subStyle;
}

void member_BStyleDocument::readDesc(BString& text, BStyle* style)
{
	text.simplify();
	text.trimmed();
	if (text.size())
	{
		BString sign;
		BString value;
		int sem_pos = text.find(':');
		if (sem_pos < text.size())
		{
			sign.reset();
			text.substr(sign, 0, sem_pos);
			sign.simplify();
			sign.trimmed();

			value.reset();
			text.substr(value, sem_pos + 1, text.size());
			value.simplify();
			value.trimmed();

			analysis(sign, value, style);
		}
		else
		{
			(BString&)message << "\tError[" << line + 1 << "] : invalid desc : " << text << '\n';
		}
	}
}
void member_BStyleDocument::analysis(BString& sign, BString& value, BStyle* style)
{
	member_BStyle* smem = style_member(style);
	if (sign.beginWith("background"))
	{
		analysisBackground(smem, sign, value);
		return;
	}
	if (sign.beginWith("border"))
	{
		analysisBorder(smem, sign, value);
		return;
	}
	if (sign.beginWith("perch"))
	{
		analysisPerch(smem, sign, value);
		return;
	}
	if (sign.beginWith("margin"))
	{
		analysisMargin(smem, sign, value);
		return;
	}
	if (sign.beginWith("text"))
	{
		analysisText(smem, sign, value);
		return;
	}
	if (sign.beginWith("font"))
	{
		analysisFont(smem, sign, value);
		return;
	}
	if (sign.beginWith("title"))
	{
		analysisTitle(smem, sign, value);
		return;
	}
	if (sign.beginWith("image"))
	{
		analysisImage(smem, sign, value);
		return;
	}
	if (sign.beginWith("icon"))
	{
		analysisIcon(smem, sign, value);
		return;
	}
	if (sign.beginWith("groove"))
	{
		analysisGroove(smem, sign, value);
		return;
	}
	if (sign.beginWith("handle"))
	{
		analysisHandle(smem, sign, value);
		return;
	}
	if (sign.beginWith("separator"))
	{
		analysisSeparator(smem, sign, value);
		return;
	}
	if (sign.beginWith("item"))
	{
		analysisItem(smem, sign, value);
		return;
	}
	if (sign.beginWith("header"))
	{
		analysisHeader(smem, sign, value);
		return;
	}
	if (sign.beginWith("arrow"))
	{
		analysisArrow(smem, sign, value);
		return;
	}
	if (sign.beginWith("grid"))
	{
		analysisGridLine(smem, sign, value);
		return;
	}
	if (sign.beginWith("graph"))
	{
		analysisGraph(smem, sign, value);
		return;
	}
	if (sign.beginWith("base"))
	{
		analysisBase(smem, sign, value);
		return;
	}
	if (sign.beginWith("radius"))
	{
		analysisRadius(smem, sign, value);
		return;
	}
	if (sign == "size")
	{
		BSize size;
		if (StringToSize(value, size))
		{
			smem->valueMap[Value_Width] = size.width();
			smem->valueMap[Value_Height] = size.height();
		}
		return;
	}
	if (sign == "width")
	{
		int width = value.toInt();
		smem->valueMap[Value_Width] = width;
		return;
	}
	if (sign == "height")
	{
		int height = value.toInt();
		smem->valueMap[Value_Height] = height;
		return;
	}
	if (sign == "form")
	{
		Form form;
		if (StringToForm(value, form))
			smem->valueMap[Value_Form] = form;
		return;
	}
	if (sign == "align")
	{
		Align align;
		if (StringToAlign(value, align))
			smem->valueMap[Value_Align] = align;
		return;
	}
	if (sign == "space" || sign == "spacing")
	{
		int space = value.toInt();
		smem->valueMap[Value_Space] = space;
		return;
	}
	if (sign == "color")
	{
		BColor color;
		if (StringToColor(value, color))
			smem->valueMap[Value_Color] = color;
		return;
	}
	if (sign == "wired")
	{
		bool wired = false;
		if (StringToBool(value, wired))
			smem->valueMap[Value_Wired] = wired;
		return;
	}
	if (sign.beginWith("wire"))
	{
		analysisWire(smem, sign, value);
		return;
	}
	if (sign == "row-space" || sign == "row-spacing")
	{
		int space = value.toInt();
		smem->valueMap[Value_Row_Space] = space;
		return;
	}
	if (sign == "column-space" || sign == "column-spacing")
	{
		int space = value.toInt();
		smem->valueMap[Value_Column_Space] = space;
		return;
	}
	if (sign == "prefix-color" || sign == "color-prefix")
	{
		BColor color;
		if (StringToColor(value, color))
			smem->colorMap[Color_Prefix] = color;
		return;
	}
	if (sign == "suffix-color" || sign == "color-suffix")
	{
		BColor color;
		if (StringToColor(value, color))
			smem->colorMap[Color_Suffix] = color;
		return;
	}
	if (sign == "*color")
	{
		resourceColor(smem, sign, value);
		return;
	}
	if (sign == "*image")
	{
		resourceImage(smem, sign, value);
		return;
	}
	if (sign == "*icon")
	{
		resourceIcon(smem, sign, value);
		return;
	}
	if (sign == "*trans")
	{
		resourceTrans(smem, sign, value);
		return;
	}
	if (sign == "flat")
	{
		bool flat = false;
		if (StringToBool(value, flat))
			smem->valueMap[Value_Flat] = flat;
		return;
	}
	if (sign == "style")
	{
		BColor color;
		if (StringToColor(value, color))
			smem->init(color);
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}

void member_BStyleDocument::analysisTitle(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "title" || sign == "title-text")
	{
		const BString& title = value;
		smem->valueMap[Value_Title] = title;
		return;
	}
	if (sign == "title-color")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title] = color;
			smem->colorMap[Color_Title_Actived] = color;
			smem->colorMap[Color_Title_Checked] = color;
			smem->colorMap[Color_Title_Hovered] = color;
			smem->colorMap[Color_Title_Pressed] = color;
			smem->colorMap[Color_Title_Disable] = color;
		}
		return;
	}
	if (sign == "title-color-normal")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title] = color;
		}
		return;
	}
	if (sign == "title-color-actived" || sign == "title-color-active")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title_Actived] = color;
		}
		return;
	}
	if (sign == "title-color-disabled" || sign == "title-color-disable")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title_Disable] = color;
		}
		return;
	}
	if (sign == "title-text-color")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title] = color;
			smem->colorMap[Color_Title_Actived] = color;
			smem->colorMap[Color_Title_Disable] = color;
		}
		return;
	}
	if (sign == "title-text-color-normal")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title_Text] = color;
		}
		return;
	}
	if (sign == "title-text-color-actived" || sign == "title-text-color-active")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title_Text_Actived] = color;
		}
		return;
	}
	if (sign == "title-text-color-disabled" || sign == "title-text-color-disable")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Title_Text_Disable] = color;
		}
		return;
	}
	if (sign == "title-image")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Title] = image;
		smem->imageMap[Image_Title_Actived] = image;
		smem->imageMap[Image_Title_Disable] = image;
		if (!image)
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : " << value << '\n';
		}
		return;
	}
	if (sign == "title-image-normal")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Title] = image;
		if (!image)
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : " << value << '\n';
		}
		return;
	}
	if (sign == "title-image-actived" || sign == "title-image-active")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Title_Actived] = image;
		if (!image)
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : " << value << '\n';
		}
		return;
	}
	if (sign == "title-image-disabled" || sign == "title-image-disable")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Title_Disable] = image;
		if (!image)
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : " << value << '\n';
		}
		return;
	}
	if (sign == "title-icon")
	{
		BIcon* icon = this->readIcon(value);
		smem->iconMap[Icon_Title] = icon;
		if (!icon)
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : " << value << '\n';
		}
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisText(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "text")
	{
		const BString& text = value;
		smem->valueMap[Value_Text] = text;
		return;
	}

	BColor color;
	if (!StringToColor(value, color))
		return;

	if (sign == "text-color")
	{
		smem->colorMap[Color_Text] = color;
		smem->colorMap[Color_Text_Actived] = color;
		smem->colorMap[Color_Text_Checked] = color;
		smem->colorMap[Color_Text_Hovered] = color;
		smem->colorMap[Color_Text_Pressed] = color;
		smem->colorMap[Color_Text_Disable] = color;
		return;
	}
	if (sign == "text-color-normal")
	{
		smem->colorMap[Color_Text] = color;
		return;
	}
	if (sign == "text-color-actived" || sign == "text-color-active")
	{
		smem->colorMap[Color_Text_Actived] = color;
		return;
	}
	if (sign == "text-color-checked" || sign == "text-color-check")
	{
		smem->colorMap[Color_Text_Checked] = color;
		return;
	}
	if (sign == "text-color-hovered" || sign == "text-color-hover")
	{
		smem->colorMap[Color_Text_Hovered] = color;
		return;
	}
	if (sign == "text-color-pressed" || sign == "text-color-press")
	{
		smem->colorMap[Color_Text_Pressed] = color;
		return;
	}
	if (sign == "text-color-disabled" || sign == "text-color-disable")
	{
		smem->colorMap[Color_Text_Disable] = color;
		return;
	}

	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisBackground(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign.beginWith("background-image"))
	{
		BImage* image = this->readImage(value);
		if (sign == "background-image")
		{
			smem->imageMap[Image_Background] = image;
			smem->imageMap[Image_Background_Actived] = image;
			smem->imageMap[Image_Background_Checked] = image;
			smem->imageMap[Image_Background_Hovered] = image;
			smem->imageMap[Image_Background_Pressed] = image;
			smem->imageMap[Image_Background_Disable] = image;
			return;
		}
		if (sign == "background-image-normal")
		{
			smem->imageMap[Image_Background] = image;
			return;
		}
		if (sign == "background-image-actived" || sign == "background-image-active")
		{
			smem->imageMap[Image_Background_Actived] = image;
			return;
		}
		if (sign == "background-image-checked" || sign == "background-image-check")
		{
			smem->imageMap[Image_Background_Checked] = image;
			return;
		}
		if (sign == "background-image-hovered" || sign == "background-image-hover")
		{
			smem->imageMap[Image_Background_Hovered] = image;
			return;
		}
		if (sign == "background-image-pressed" || sign == "background-image-press")
		{
			smem->imageMap[Image_Background_Pressed] = image;
			return;
		}
		if (sign == "background-image-disabled" || sign == "background-image-disable")
		{
			smem->imageMap[Image_Background_Disable] = image;
			return;
		}
		return;
	}

	value.remove("-color");
	BColor color;
	if (!StringToColor(value, color))
	{
		return;
	}

	if (sign == "background")
	{
		smem->colorMap[Color_Background] = color;
		smem->colorMap[Color_Background_Actived] = color;
		smem->colorMap[Color_Background_Checked] = color;
		smem->colorMap[Color_Background_Hovered] = color;
		smem->colorMap[Color_Background_Pressed] = color;
		smem->colorMap[Color_Background_Disable] = color;
		return;
	}
	if (sign == "background-normal")
	{
		smem->colorMap[Color_Background] = color;
		return;
	}
	if (sign == "background-actived" || sign == "background-active")
	{
		smem->colorMap[Color_Background_Actived] = color;
		return;
	}
	if (sign == "background-checked" || sign == "background-check")
	{
		smem->colorMap[Color_Background_Checked] = color;
		return;
	}
	if (sign == "background-hovered" || sign == "background-hover")
	{
		smem->colorMap[Color_Background_Hovered] = color;
		return;
	}
	if (sign == "background-pressed" || sign == "background-press")
	{
		smem->colorMap[Color_Background_Pressed] = color;
		return;
	}
	if (sign == "background-disabled" || sign == "background-disable")
	{
		smem->colorMap[Color_Background_Disable] = color;
		return;
	}

	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisBorder(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "border" || sign == "border-width" || sign == "border-size")
	{
		int border = value.toInt();
		smem->valueMap[Value_Border] = border;
		return;
	}

	if (sign.beginWith("border-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : invalid color desc." << '\n';
			return;
		}
		if (sign == "border-color")
		{
			smem->colorMap[Color_Border] = color;
			smem->colorMap[Color_Border_Actived] = color;
			smem->colorMap[Color_Border_Checked] = color;
			smem->colorMap[Color_Border_Hovered] = color;
			smem->colorMap[Color_Border_Pressed] = color;
			smem->colorMap[Color_Border_Disable] = color;
			return;
		}
		if (sign == "border-color-normal")
		{
			smem->colorMap[Color_Border] = color;
			return;
		}
		if (sign == "border-color-actived" || sign == "border-color-active")
		{
			smem->colorMap[Color_Border_Actived] = color;
			return;
		}
		if (sign == "border-color-checked" || sign == "border-color-check")
		{
			smem->colorMap[Color_Border_Checked] = color;
			return;
		}
		if (sign == "border-color-hovered" || sign == "border-color-hover")
		{
			smem->colorMap[Color_Border_Hovered] = color;
			return;
		}
		if (sign == "border-color-pressed" || sign == "border-color-press")
		{
			smem->colorMap[Color_Border_Pressed] = color;
			return;
		}
		if (sign == "border-color-disabled" || sign == "border-color-disable")
		{
			smem->colorMap[Color_Border_Disable] = color;
			return;
		}
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisPerch(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "perch")
	{
		BStringList words;
		value.split(words, ',');
		if (words.size() == 1)
		{
			int perch = words[0].toInt();
			smem->valueMap[Value_Perch_Left] = perch;
			smem->valueMap[Value_Perch_Top] = perch;
			smem->valueMap[Value_Perch_Right] = perch;
			smem->valueMap[Value_Perch_Bottom] = perch;
			return;
		}
		if (words.size() == 4)
		{
			smem->valueMap[Value_Perch_Left] = words[0].toInt();
			smem->valueMap[Value_Perch_Top] = words[1].toInt();
			smem->valueMap[Value_Perch_Right] = words[2].toInt();
			smem->valueMap[Value_Perch_Bottom] = words[3].toInt();
			return;
		}
		return;
	}
	if (sign == "perch-left")
	{
		int left = value.toInt();
		smem->valueMap[Value_Perch_Left] = left;
		return;
	}
	if (sign == "perch-right")
	{
		int right = value.toInt();
		smem->valueMap[Value_Perch_Right] = right;
		return;
	}
	if (sign == "perch-top")
	{
		int top = value.toInt();
		smem->valueMap[Value_Perch_Top] = top;
		return;
	}
	if (sign == "perch-bottom")
	{
		int bottom = value.toInt();
		smem->valueMap[Value_Perch_Bottom] = bottom;
		return;
	}

	if (sign.beginWith("perch-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : invalid color desc." << '\n';
			return;
		}
		if (sign == "perch-color")
		{
			smem->colorMap[Color_Perch] = color;
			smem->colorMap[Color_Perch_Actived] = color;
			smem->colorMap[Color_Perch_Checked] = color;
			smem->colorMap[Color_Perch_Hovered] = color;
			smem->colorMap[Color_Perch_Pressed] = color;
			smem->colorMap[Color_Perch_Disable] = color;
			return;
		}
		if (sign == "perch-color-normal")
		{
			smem->colorMap[Color_Perch] = color;
			return;
		}
		if (sign == "perch-color-actived" || sign == "perch-color-active")
		{
			smem->colorMap[Color_Perch_Actived] = color;
			return;
		}
		if (sign == "perch-color-checked" || sign == "perch-color-check")
		{
			smem->colorMap[Color_Perch_Checked] = color;
			return;
		}
		if (sign == "perch-color-hovered" || sign == "perch-color-hover")
		{
			smem->colorMap[Color_Perch_Hovered] = color;
			return;
		}
		if (sign == "perch-color-pressed" || sign == "perch-color-press")
		{
			smem->colorMap[Color_Perch_Pressed] = color;
			return;
		}
		if (sign == "perch-color-disabled" || sign == "perch-color-disable")
		{
			smem->colorMap[Color_Perch_Disable] = color;
			return;
		}
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisMargin(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "margin")
	{
		BStringList words;
		value.split(words, ',');
		if (words.size() == 1)
		{
			int perch = words[0].toInt();
			smem->valueMap[Value_Margin_Left] = perch;
			smem->valueMap[Value_Margin_Top] = perch;
			smem->valueMap[Value_Margin_Right] = perch;
			smem->valueMap[Value_Margin_Bottom] = perch;
			return;
		}
		if (words.size() == 2)
		{
			int hperch = words[0].toInt();
			smem->valueMap[Value_Margin_Left] = hperch;
			smem->valueMap[Value_Margin_Right] = hperch;
			int vperch = words[1].toInt();
			smem->valueMap[Value_Margin_Top] = vperch;
			smem->valueMap[Value_Margin_Bottom] = vperch;
			return;
		}
		if (words.size() == 4)
		{
			smem->valueMap[Value_Margin_Left] = words[0].toInt();
			smem->valueMap[Value_Margin_Top] = words[1].toInt();
			smem->valueMap[Value_Margin_Right] = words[2].toInt();
			smem->valueMap[Value_Margin_Bottom] = words[3].toInt();
			return;
		}
		return;
	}
	if (sign == "margin-left")
	{
		int left = value.toInt();
		smem->valueMap[Value_Margin_Left] = left;
		return;
	}
	if (sign == "margin-right")
	{
		int right = value.toInt();
		smem->valueMap[Value_Margin_Right] = right;
		return;
	}
	if (sign == "margin-top")
	{
		int top = value.toInt();
		smem->valueMap[Value_Margin_Top] = top;
		return;
	}
	if (sign == "margin-bottom")
	{
		int bottom = value.toInt();
		smem->valueMap[Value_Margin_Bottom] = bottom;
		return;
	}

	if (sign.beginWith("margin-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : invalid color desc." << '\n';
			return;
		}
		if (sign == "margin-color")
		{
			smem->colorMap[Color_Margin] = color;
			smem->colorMap[Color_Margin_Actived] = color;
			smem->colorMap[Color_Margin_Checked] = color;
			smem->colorMap[Color_Margin_Hovered] = color;
			smem->colorMap[Color_Margin_Pressed] = color;
			smem->colorMap[Color_Margin_Disable] = color;
			return;
		}
		if (sign == "margin-color-normal")
		{
			smem->colorMap[Color_Margin] = color;
			return;
		}
		if (sign == "margin-color-actived" || sign == "margin-color-active")
		{
			smem->colorMap[Color_Margin_Actived] = color;
			return;
		}
		if (sign == "margin-color-checked" || sign == "margin-color-check")
		{
			smem->colorMap[Color_Margin_Checked] = color;
			return;
		}
		if (sign == "margin-color-hovered" || sign == "margin-color-hover")
		{
			smem->colorMap[Color_Margin_Hovered] = color;
			return;
		}
		if (sign == "margin-color-pressed" || sign == "margin-color-press")
		{
			smem->colorMap[Color_Margin_Pressed] = color;
			return;
		}
		if (sign == "margin-color-disabled" || sign == "margin-color-disable")
		{
			smem->colorMap[Color_Margin_Disable] = color;
			return;
		}
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisRadius(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "radius")
	{
		if (value.contain(','))
		{
			BStringList words;
			value.split(words, ',');
			if (words.size() == 4)
			{
				smem->valueMap[Value_Radius_Left_Top] = BSize(words[0].toInt());
				smem->valueMap[Value_Radius_Right_Top] = BSize(words[1].toInt());
				smem->valueMap[Value_Radius_Right_Bottom] = BSize(words[2].toInt());
				smem->valueMap[Value_Radius_Left_Bottom] = BSize(words[3].toInt());
			}
			return;
		}
		BSize radius;
		if (StringToSize(value, radius))
		{
			smem->valueMap[Value_Radius_Left_Top] = radius;
			smem->valueMap[Value_Radius_Right_Top] = radius;
			smem->valueMap[Value_Radius_Right_Bottom] = radius;
			smem->valueMap[Value_Radius_Left_Bottom] = radius;
		}
		return;
	}
	if (sign == "radius-left-top" || sign == "radius-top-left")
	{
		BSize radius;
		if (StringToSize(value, radius))
			smem->valueMap[Value_Radius_Left_Top] = radius;
		return;
	}
	if (sign == "radius-right-top" || sign == "radius-top-right")
	{
		BSize radius;
		if (StringToSize(value, radius))
			smem->valueMap[Value_Radius_Right_Top] = radius;
		return;
	}
	if (sign == "radius-right-bottom" || sign == "radius-bottom-right")
	{
		BSize radius;
		if (StringToSize(value, radius))
			smem->valueMap[Value_Radius_Right_Bottom] = radius;
		return;
	}
	if (sign == "radius-left-bottom" || sign == "radius-bottom-left")
	{
		BSize radius;
		if (StringToSize(value, radius))
			smem->valueMap[Value_Radius_Left_Bottom] = radius;
		return;
	}

	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisFont(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "font")
	{
		BStringList words;
		if (0 == value.split(words, ','))
			return;
		BFont* font = smem->namedFontMap(BString());
		if (font == 0)
		{
			font = new BFont(words[0]);
			smem->namedFontMap[BString()] = font;
		}
		if (words.size() > 1)
		{
			font->setSize(words[1].toInt());
		}
		return;
	}
	if (sign == "font-family")
	{
		if (value.empty())
			return;
		BFont* font = smem->namedFontMap(BString());
		if (font == 0)
		{
			font = new BFont();
			smem->namedFontMap[BString()] = font;
		}
		font->setFamily(value);
		return;
	}
	if (sign == "font-size")
	{
		int size = value.toInt();
		BFont* font = smem->namedFontMap(BString());
		if (font == 0)
		{
			font = new BFont(*app_style->font());
			smem->namedFontMap[BString()] = font;
		}
		font->setSize(size);
		return;
	}
}
void member_BStyleDocument::analysisGroove(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "groove-size")
	{
		int size = value.toInt();
		smem->valueMap[Value_Groove_Size] = size;
		return;
	}
	if (sign == "groove-color")
	{
		BColor color;
		if (!StringToColor(value, color))
			return;
		smem->colorMap[Color_Groove] = color;
		return;
	}
	if (sign == "groove-image")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Groove] = image;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisGraph(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "graph")
	{
		Graph graph = Graph_None;
		if (value == "space")
			graph = Graph_Space;
		else if (value == "circle")
			graph = Graph_Circle;
		else if (value == "circle-fill")
			graph = Graph_Circle_Fill;
		else if (value == "square")
			graph = Graph_Square;
		else if (value == "square-fill")
			graph = Graph_Square_Fill;
		else if (value == "arrow-up")
			graph = Graph_Arrow_Up;
		else if (value == "arrow-up-fill")
			graph = Graph_Arrow_Up_Fill;
		else if (value == "arrow-down")
			graph = Graph_Arrow_Down;
		else if (value == "arrow-down-fill")
			graph = Graph_Arrow_Down_Fill;
		else if (value == "arrow-left")
			graph = Graph_Arrow_Left;
		else if (value == "arrow-left-fill")
			graph = Graph_Arrow_Left_Fill;
		else if (value == "arrow-right")
			graph = Graph_Arrow_Right;
		else if (value == "arrow-right-fill")
			graph = Graph_Arrow_Right_Fill;
		else if (value == "plus")
			graph = Graph_Plus;
		else if (value == "minus")
			graph = Graph_Minus;
		else if (value == "check")
			graph = Graph_Check;
		else if (value == "cross")
			graph = Graph_Cross;
		else if (value == "maximize")
			graph = Graph_Maximize;
		else if (value == "minimize")
			graph = Graph_Minimize;
		smem->valueMap[Value_Graph] = graph;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisIcon(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "icon")
	{
		BIconHolder icon = this->readIcon(value);
		smem->valueMap[Value_Icon] = icon;
		return;
	}
	if (sign == "icon-size")
	{
		int w = value.toInt();
		BSize size(w, w);
		int comma_pos = value.find(',');
		value.remove(0, comma_pos + 1);
		value.trimmed();
		if (value.size())
		{
			size.height() = value.toInt();
		}
		smem->valueMap[Value_Icon_Size] = size;
		return;
	}
	if (sign == "icon-expand")
	{
		BIconHolder icon = this->readIcon(value);
		smem->iconMap[Icon_Expand] = icon;
		return;
	}
	if (sign == "icon-shrink")
	{
		BIconHolder icon = this->readIcon(value);
		smem->iconMap[Icon_Shrink] = icon;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisImage(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "image")
	{
		BImage* image = this->readImage(value);
		smem->valueMap[Value_Image] = image;
		return;
	}
	if (sign == "image-size")
	{
		int w = value.toInt();
		BSize size(w, w);
		int comma_pos = value.find(',');
		value.remove(0, comma_pos + 1);
		value.trimmed();
		if (value.size())
		{
			size.height() = value.toInt();
		}
		smem->valueMap[Value_Image_Size] = size;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisBase(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "base-size")
	{
		BSize size;
		if (StringToSize(value, size))
			smem->valueMap[Value_Base_Size] = size;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisArrow(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "arrow-size")
	{
		BSize size;
		if (StringToSize(value, size))
			smem->valueMap[Value_Arrow_Size] = size;
		return;
	}

	if (sign == "arrow-align")
	{
		Align align = Align_None;
		if (StringToAlign(value, align))
			smem->valueMap[Value_Arrow_Align] = align;
		return;
	}

	if (sign.beginWith("arrow-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : invalid color desc." << '\n';
			return;
		}
		if (sign == "arrow-color")
		{
			smem->colorMap[Color_Arrow] = color;
			smem->colorMap[Color_Arrow_Actived] = color;
			smem->colorMap[Color_Arrow_Checked] = color;
			smem->colorMap[Color_Arrow_Hovered] = color;
			smem->colorMap[Color_Arrow_Pressed] = color;
			smem->colorMap[Color_Arrow_Disable] = color;
			return;
		}
		if (sign == "arrow-color-normal")
		{
			smem->colorMap[Color_Arrow] = color;
			return;
		}
		if (sign == "arrow-color-actived" || sign == "arrow-color-active")
		{
			smem->colorMap[Color_Arrow_Actived] = color;
			return;
		}
		if (sign == "arrow-color-checked" || sign == "arrow-color-check")
		{
			smem->colorMap[Color_Arrow_Checked] = color;
			return;
		}
		if (sign == "arrow-color-hovered" || sign == "arrow-color-hover")
		{
			smem->colorMap[Color_Arrow_Hovered] = color;
			return;
		}
		if (sign == "arrow-color-pressed" || sign == "arrow-color-press")
		{
			smem->colorMap[Color_Arrow_Pressed] = color;
			return;
		}
		if (sign == "arrow-color-disabled" || sign == "arrow-color-disable")
		{
			smem->colorMap[Color_Arrow_Disable] = color;
			return;
		}
		(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
		return;
	}
	if (sign.beginWith("arrow-icon"))
	{
		BIcon* icon = this->readIcon(value);
		if (!icon)
		{
			(BString&)message << "\tError[" << line + 1 << "] : arrow icon " << sign << " lost." << '\n';
			return;
		}
		if (sign == "arrow-icon")
		{
			smem->iconMap[Icon_Arrow_Up] = icon;
			smem->iconMap[Icon_Arrow_Down] = icon;
			smem->iconMap[Icon_Arrow_Left] = icon;
			smem->iconMap[Icon_Arrow_Right] = icon;
			return;
		}
		if (sign == "arrow-icon-up" || sign == "arrow-up-icon")
		{
			smem->iconMap[Icon_Arrow_Up] = icon;
			return;
		}
		if (sign == "arrow-icon-down" || sign == "arrow-down-icon")
		{
			smem->iconMap[Icon_Arrow_Down] = icon;
			return;
		}
		if (sign == "arrow-icon-left" || sign == "arrow-left-icon")
		{
			smem->iconMap[Icon_Arrow_Left] = icon;
			return;
		}
		if (sign == "arrow-icon-right" || sign == "arrow-right-icon")
		{
			smem->iconMap[Icon_Arrow_Right] = icon;
			return;
		}
		(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisHandle(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "handle" || sign == "handle-size")
	{
		int handle = value.toInt();
		if (handle > 2 && handle < 300)
			smem->valueMap[Value_Handle_Size] = handle;
		return;
	}
	if (sign.beginWith("handle-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
		{
			(BString&)message << "\tError[" << line + 1 << "] : " << sign << " : invalid color desc." << '\n';
			return;
		}
		if (sign == "handle-color")
		{
			smem->colorMap[Color_Handle] = color;
			smem->colorMap[Color_Handle_Actived] = color;
			smem->colorMap[Color_Handle_Checked] = color;
			smem->colorMap[Color_Handle_Hovered] = color;
			smem->colorMap[Color_Handle_Pressed] = color;
			smem->colorMap[Color_Handle_Disable] = color;
			return;
		}
		if (sign == "handle-color-normal")
		{
			smem->colorMap[Color_Handle] = color;
			return;
		}
		if (sign == "handle-color-actived" || sign == "handle-color-active")
		{
			smem->colorMap[Color_Handle_Actived] = color;
			return;
		}
		if (sign == "handle-color-hovered" || sign == "handle-color-hover")
		{
			smem->colorMap[Color_Handle_Hovered] = color;
			return;
		}
		if (sign == "handle-color-pressed" || sign == "handle-color-press")
		{
			smem->colorMap[Color_Handle_Pressed] = color;
			return;
		}
		if (sign == "handle-color-disabled" || sign == "handle-color-disable")
		{
			smem->colorMap[Color_Handle_Disable] = color;
			return;
		}
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisWire(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "wire")
	{
		int size = value.toInt();
		smem->valueMap[Value_Wire_Size] = size;
		return;
	}
	if (sign == "wire-size" || sign == "wire-width")
	{
		int size = value.toInt();
		smem->valueMap[Value_Wire_Size] = size;
		return;
	}
	if (sign == "wire-color")
	{
		BColor color;
		if (StringToColor(value, color))
			smem->colorMap[Color_Wire] = color;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisSeparator(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "separator-color")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Separator] = color;
		}
		return;
	}
	if (sign == "separator-image")
	{
		BImage* image = this->readImage(value);
		smem->imageMap[Image_Separator] = image;
		return;
	}
	if (sign == "separator" || sign == "separator-size")
	{
		BSize size;
		if (StringToSize(value, size))
			smem->valueMap[Value_Separator_Size] = size;
		return;
	}
	if (sign == "indicator" || sign == "indicator-size")
	{
		BSize size;
		if (StringToSize(value, size))
			smem->valueMap[Value_Indicator_Size] = size;
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisGridLine(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign == "grid" || sign == "grid-style")
	{
		GridStyle gridStyle = Grid_None;
		if (value == "vertical")
			gridStyle = Grid_Vertical;
		if (value == "horizontal")
			gridStyle = Grid_Horizontal;
		if (value == "crossing")
			gridStyle = Grid_Crossing;
		smem->valueMap[Value_Grid_Style] = gridStyle;
		return;
	}
	if (sign == "grid-color")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Grid_Hor] = color;
			smem->colorMap[Color_Grid_Ver] = color;
		}
		return;
	}
	if (sign == "grid-color-ver")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Grid_Ver] = color;
		}
		return;
	}
	if (sign == "grid-color-hor")
	{
		BColor color;
		if (StringToColor(value, color))
		{
			smem->colorMap[Color_Grid_Hor] = color;
		}
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisHeader(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign.beginWith("header-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
			return;
		if (sign == "header-color")
		{
			smem->colorMap[Color_Header] = color;
			smem->colorMap[Color_Header_Actived] = color;
			smem->colorMap[Color_Header_Checked] = color;
			smem->colorMap[Color_Header_Hovered] = color;
			smem->colorMap[Color_Header_Pressed] = color;
			smem->colorMap[Color_Header_Disable] = color;
			return;
		}
		if (sign == "header-color-normal")
		{
			smem->colorMap[Color_Header] = color;
			return;
		}
		if (sign == "header-color-actived")
		{
			smem->colorMap[Color_Header_Actived] = color;
			return;
		}
		if (sign == "header-color-checked")
		{
			smem->colorMap[Color_Header_Checked] = color;
			return;
		}
		if (sign == "header-color-hovered")
		{
			smem->colorMap[Color_Header_Hovered] = color;
			return;
		}
		if (sign == "header-color-pressed")
		{
			smem->colorMap[Color_Header_Pressed] = color;
			return;
		}
		if (sign == "header-color-disable")
		{
			smem->colorMap[Color_Header_Disable] = color;
			return;
		}
		return;
	}
	if (sign.beginWith("header-image"))
	{
		BImage* image = this->readImage(value);
		if (sign == "header-image")
		{
			smem->imageMap[Image_Header] = image;
			smem->imageMap[Image_Header_Actived] = image;
			smem->imageMap[Image_Header_Checked] = image;
			smem->imageMap[Image_Header_Hovered] = image;
			smem->imageMap[Image_Header_Pressed] = image;
			smem->imageMap[Image_Header_Disable] = image;
			return;
		}
		if (sign == "header-image-normal")
		{
			smem->imageMap[Image_Header] = image;
			return;
		}
		if (sign == "header-image-checked")
		{
			smem->imageMap[Image_Header_Checked] = image;
			return;
		}
		if (sign == "header-image-hovered")
		{
			smem->imageMap[Image_Header_Hovered] = image;
			return;
		}
		if (sign == "header-image-pressed")
		{
			smem->imageMap[Image_Header_Pressed] = image;
			return;
		}
		if (sign == "header-image-disabled")
		{
			smem->imageMap[Image_Header_Disable] = image;
			return;
		}
		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}
void member_BStyleDocument::analysisItem(member_BStyle* smem, BString& sign, BString& value)
{
	if (sign.beginWith("item-color"))
	{
		BColor color;
		if (!StringToColor(value, color))
			return;
		if (sign == "item-color")
		{
			smem->colorMap[Color_Item] = color;
			smem->colorMap[Color_Item_Actived] = color;
			smem->colorMap[Color_Item_Checked] = color;
			smem->colorMap[Color_Item_Hovered] = color;
			smem->colorMap[Color_Item_Pressed] = color;
			smem->colorMap[Color_Item_Disable] = color;
			return;
		}
		if (sign == "item-color-normal")
		{
			smem->colorMap[Color_Item] = color;
			return;
		}
		if (sign == "item-color-actived")
		{
			smem->colorMap[Color_Item_Actived] = color;
			return;
		}
		if (sign == "item-color-checked")
		{
			smem->colorMap[Color_Item_Checked] = color;
			return;
		}
		if (sign == "item-color-hovered")
		{
			smem->colorMap[Color_Item_Hovered] = color;
			return;
		}
		if (sign == "item-color-pressed")
		{
			smem->colorMap[Color_Item_Pressed] = color;
			return;
		}
		if (sign == "item-color-disable")
		{
			smem->colorMap[Color_Item_Disable] = color;
			return;
		}
		return;
	}
	if (sign.beginWith("item-image"))
	{
		BImage* image = this->readImage(value);
		if (sign == "item-image")
		{
			smem->imageMap[Image_Item] = image;
			smem->imageMap[Image_Item_Actived] = image;
			smem->imageMap[Image_Item_Checked] = image;
			smem->imageMap[Image_Item_Hovered] = image;
			smem->imageMap[Image_Item_Pressed] = image;
			smem->imageMap[Image_Item_Disable] = image;
			return;
		}
		if (sign == "item-image-normal")
		{
			smem->imageMap[Image_Item] = image;
			return;
		}
		if (sign == "item-image-actived")
		{
			smem->imageMap[Image_Item_Actived] = image;
			return;
		}
		if (sign == "item-image-checked")
		{
			smem->imageMap[Image_Item_Checked] = image;
			return;
		}
		if (sign == "item-image-hovered")
		{
			smem->imageMap[Image_Item_Hovered] = image;
			return;
		}
		if (sign == "item-image-pressed")
		{
			smem->imageMap[Image_Item_Pressed] = image;
			return;
		}
		if (sign == "item-image-disable")
		{
			smem->imageMap[Image_Item_Disable] = image;
			return;
		}

		return;
	}
	(BString&)message << "\tError[" << line + 1 << "] : unknown sign : " << sign << '\n';
}

void member_BStyleDocument::resourceFont(member_BStyle* smem, BString& sign, BString& value)
{
	BString word;
	int pos = value.find(',');
	value.substr(word, 0, pos);
	BFont* font = new BFont(word);
	smem->namedFontMap[sign] = font;
	if (pos < value.size())
	{
		value.substr(word, pos + 1);
		font->setSize(word.toInt());
	}
	return;
}
void member_BStyleDocument::resourceColor(member_BStyle* smem, BString& sign, BString& value)
{
	int sem_pos = value.find(':');
	if (sem_pos < value.size())
	{
		BString name;
		value.substr(name, 0, sem_pos);
		name.trimmed();
		if (name.empty())
			return;
		value.remove(0, sem_pos + 1);
		value.trimmed();
		if (smem->namedColorMap.contain(name))
		{
			(BString&)message << "\tWarning : redefine color [" << name << "] " << value << '\n';
		}
		BColor color;
		if (StringToColor(value, color))
		{
			smem->namedColorMap[name] = color;
		}
	}
}
void member_BStyleDocument::resourceImage(member_BStyle* smem, BString& sign, BString& value)
{
	int sem_pos = value.find(':');
	if (sem_pos < value.size())
	{
		BString name;
		value.substr(name, 0, sem_pos);
		name.trimmed();
		if (name.empty())
			return;
		value.remove(0, sem_pos + 1);
		value.trimmed();
		if (value.beginWith("./"))
			value.remove(0, 2);
		BImage* image = this->readImage(value);
		if (image == 0)
		{
			(BString&)message << "\tError[" << line + 1 << "] : load image failed : " << name << " : " << value << '\n';
		}
		if (smem->namedImageMap.contain(name))
		{
			(BString&)message << "\tWarning : redefine image [" << name << "] " << value << '\n';
		}
		smem->namedImageMap[name] = image;
	}
}
void member_BStyleDocument::resourceIcon(member_BStyle* smem, BString& sign, BString& value)
{
	int sem_pos = value.find(':');
	if (sem_pos < value.size())
	{
		BString name;
		value.substr(name, 0, sem_pos);
		name.trimmed();
		if (name.empty())
			return;
		value.remove(0, sem_pos + 1);
		value.trimmed();
		if (value.beginWith("./"))
			value.remove(0, 2);
		BIconHolder icon = this->readIcon(value);
		if (icon.empty())
		{
			(BString&)message << "\tError[" << line + 1 << "] : load icon failed : " << name << " : " << value << '\n';
		}
		if (smem->namedIconMap.contain(name))
		{
			(BString&)message << "\tWarning[" << line + 1 << "] : redefine icon " << name << " " << value << '\n';
		}
		smem->namedIconMap[name] = icon;
	}
}
void member_BStyleDocument::resourceTrans(member_BStyle* smem, BString& sign, BString& value)
{
	int sem_pos = 0;
	while (sem_pos < value.size())
	{
		if (value[sem_pos] == '\\')
		{
			value.remove(sem_pos);
			char n = value[sem_pos];
			if (n == 't')
				value[sem_pos] = '\t';
			if (n == 'n')
				value[sem_pos] = '\n';
			sem_pos++;
			continue;
		}
		if (value[sem_pos] == ':')
			break;
		sem_pos++;
	}
	if (sem_pos < value.size())
	{
		BString text;
		value.substr(text, 0, sem_pos);
		value.remove(0, sem_pos + 1);
		text.trimmed();
		text.lower();
		value.trimmed();
		if (text.size() && value.size())
		{
			if (smem->transMap.contain(text))
			{
				(BString&)message << "\tWarning : redefine trans [" << text << "] " << value << '\n';
			}
			smem->transMap[text] = value;
		}
	}
	else
	{
		(BString&)message << "\tError[" << line + 1 << "] : invalid text." << value << '\n';
	}
}

BImage* member_BStyleDocument::readImage(const BString& fileName)
{
	if (fileName == "empty")
		return 0;
	BImage* image = imageMap(fileName);
	if (!image && path.size())
	{
		BString filePath;
		filePath << path << '/' << fileName;
		if (BFile::Exist(filePath))
			image = ReadFile<BImage>(filePath);
	}
	if (!image)
	{
		if (BFile::Exist(fileName))
			image = ReadFile<BImage>(fileName);
	}
	if (!image)
	{
		(BString&)message << "\tError[" << line + 1 << "] : can't read image : " << fileName << '\n';
	}
	imageMap[fileName] = image;
	return image;
}
BIcon* member_BStyleDocument::readIcon(const BString& fileName)
{
	if (fileName.ext())
	{
		if (BImage* image = readImage(fileName))
		{
			BIcon* icon = new BIcon(image);
			return icon;
		}
		return 0;
	}
	BIcon* icon = new BIcon();
	if (path.size())
	{
		BString filePath;
		filePath << path << '/' << fileName;
		icon->reset(filePath);
	}
	if (icon->empty())
	{
		icon->reset(fileName);
	}
	if (icon->empty())
	{
		(BString&)message << "\tError[" << line + 1 << "] : can't load icon : " << fileName << '\n';
	}
	return icon;
}

void member_BStyleDocument::assemble(BString& text, StyleRole srole, const BValue& value)
{
	switch (srole)
	{
	case Value_Icon:	assembleIcon(text, "icon", value);		break;
	case Value_Image:	assembleImage(text, "image", value);	break;
	case Value_Graph:	assembleGraph(text, "graph", value);	break;
	case Value_Title:	assembleString(text, "title", value);	break;
	case Value_Width:	assembleInt(text, "width", value);		break;
	case Value_Height:	assembleInt(text, "height", value);		break;
	case Value_Form:	assembleForm(text, "form", value);		break;
	case Value_Align:	assembleAlign(text, "align", value);	break;
	case Value_Space:	assembleInt(text, "spacing", value);	break;
	case Value_Border:	assembleInt(text, "border", value);		break;
	case Value_Flat:	assembleBool(text, "flat", value);		break;
	case Value_Wired:	assembleBool(text, "wired", value);		break;

	case Value_Perch_Left:		assembleInt(text, "perch-left", value);		break;
	case Value_Perch_Right:		assembleInt(text, "perch-right", value);	break;
	case Value_Perch_Top:		assembleInt(text, "perch-top", value);		break;
	case Value_Perch_Bottom:	assembleInt(text, "perch-bottom", value);	break;

	case Value_Margin_Left:		assembleInt(text, "margin-left", value);	break;
	case Value_Margin_Right:	assembleInt(text, "margin-right", value);	break;
	case Value_Margin_Top:		assembleInt(text, "margin-top", value);		break;
	case Value_Margin_Bottom:	assembleInt(text, "margin-bottom", value);	break;

	case Value_Icon_Size:		assembleSize(text, "size", value);			break;
	case Value_Handle_Size:		assembleSize(text, "handle-size", value);	break;
	case Value_Wire_Size:		assembleInt(text, "wire-size", value);		break;
	case Value_Row_Space:		assembleInt(text, "row-spacing", value);	break;
	case Value_Column_Space:	assembleInt(text, "column-spacing", value);	break;
	case Value_Grid_Style:		assmbleGridStyle(text, "grid-style", value);break;
	case Value_Groove_Size:		assembleInt(text, "groove-size", value);	break;
	case Value_Separator_Size:	assembleSize(text, "separator-size", value);break;
	case Value_Indicator_Size:	assembleSize(text, "indicator-size", value);break;

	case Value_Arrow_Size:		assembleSize(text, "arrow-size", value);	break;
	case Value_Arrow_Align:		assembleInt(text, "arrow-align", value);	break;
	case Value_Arrow_Graph:		assembleGraph(text, "arrow-graph", value);	break;

	case Value_Radius_Left_Top:		assembleSize(text, "radius-left-top", value);	break;
	case Value_Radius_Right_Top:	assembleSize(text, "radius-right-top", value);	break;
	case Value_Radius_Left_Bottom:	assembleSize(text, "radius-left-bottom", value); break;
	case Value_Radius_Right_Bottom:	assembleSize(text, "radius-right-bottom", value); break;
		
	case Color_Title:			assembleColor(text, "title-color-normal", value);	break;
	case Color_Title_Actived:	assembleColor(text, "title-color-actived", value);	break;
	case Color_Title_Hovered:	assembleColor(text, "title-color-hovered", value);	break;
	case Color_Title_Pressed:	assembleColor(text, "title-color-pressed", value);	break;
	case Color_Title_Checked:	assembleColor(text, "title-color-checked", value);	break;
	case Color_Title_Disable:	assembleColor(text, "title-color-disable", value);	break;
		
	case Color_Title_Text:			assembleColor(text, "title-text-color-normal", value);	break;
	case Color_Title_Text_Actived:	assembleColor(text, "title-text-color-actived", value);	break;
	case Color_Title_Text_Checked:	assembleColor(text, "title-text-color-checked", value);	break;
	case Color_Title_Text_Hovered:	assembleColor(text, "title-text-color-hovered", value);	break;
	case Color_Title_Text_Pressed:	assembleColor(text, "title-text-color-pressed", value);	break;
	case Color_Title_Text_Disable:	assembleColor(text, "title-text-color-disable", value);	break;

	case Color_Text:			assembleColor(text, "text-color-normal", value);	break;
	case Color_Text_Actived:	assembleColor(text, "text-color-actived", value);	break;
	case Color_Text_Checked:	assembleColor(text, "text-color-checked", value);	break;
	case Color_Text_Hovered:	assembleColor(text, "text-color-hovered", value);	break;
	case Color_Text_Pressed:	assembleColor(text, "text-color-pressed", value);	break;
	case Color_Text_Disable:	assembleColor(text, "text-color-disable", value);	break;

	case Color_Background:			assembleColor(text, "background-normal", value);	break;
	case Color_Background_Actived:	assembleColor(text, "background-actived", value);	break;
	case Color_Background_Checked:	assembleColor(text, "background-checked", value);	break;
	case Color_Background_Hovered:	assembleColor(text, "background-hovered", value);	break;
	case Color_Background_Pressed:	assembleColor(text, "background-pressed", value);	break;
	case Color_Background_Disable:	assembleColor(text, "background-disable", value);	break;

	case Color_Border:			assembleColor(text, "border-color-normal", value);		break;
	case Color_Border_Actived:	assembleColor(text, "border-color-actived", value);		break;
	case Color_Border_Checked:	assembleColor(text, "border-color-checked", value);		break;
	case Color_Border_Hovered:	assembleColor(text, "border-color-hovered", value);		break;
	case Color_Border_Pressed:	assembleColor(text, "border-color-pressed", value);		break;
	case Color_Border_Disable:	assembleColor(text, "border-color-disable", value);		break;
		
	case Color_Perch:			assembleColor(text, "perch-color-normal", value);		break;
	case Color_Perch_Actived:	assembleColor(text, "perch-color-actived", value);		break;
	case Color_Perch_Checked:	assembleColor(text, "perch-color-checked", value);		break;
	case Color_Perch_Hovered:	assembleColor(text, "perch-color-hovered", value);		break;
	case Color_Perch_Pressed:	assembleColor(text, "perch-color-pressed", value);		break;
	case Color_Perch_Disable:	assembleColor(text, "perch-color-disable", value);		break;
		
	case Color_Margin:			assembleColor(text, "margin-color-normal", value);		break;
	case Color_Margin_Actived:	assembleColor(text, "margin-color-actived", value);		break;
	case Color_Margin_Hovered:	assembleColor(text, "margin-color-hovered", value);		break;
	case Color_Margin_Pressed:	assembleColor(text, "margin-color-pressed", value);		break;
	case Color_Margin_Checked:	assembleColor(text, "margin-color-checked", value);		break;
	case Color_Margin_Disable:	assembleColor(text, "margin-color-disable", value);		break;
		
	case Color_Handle:			assembleColor(text, "handle-color-normal", value);		break;
	case Color_Handle_Actived:	assembleColor(text, "handle-color-actived", value);		break;
	case Color_Handle_Hovered:	assembleColor(text, "handle-color-hovered", value);		break;
	case Color_Handle_Pressed:	assembleColor(text, "handle-color-pressed", value);		break;
	case Color_Handle_Checked:	assembleColor(text, "handle-color-checked", value);		break;
	case Color_Handle_Disable:	assembleColor(text, "handle-color-disable", value);		break;

	case Color_Arrow:			assembleColor(text, "arrow-color-normal", value);		break;
	case Color_Arrow_Hovered:	assembleColor(text, "arrow-color-hovered", value);		break;
	case Color_Arrow_Pressed:	assembleColor(text, "arrow-color-pressed", value);		break;
	case Color_Arrow_Checked:	assembleColor(text, "arrow-color-checked", value);		break;
	case Color_Arrow_Disable:	assembleColor(text, "arrow-color-disable", value);		break;

	case Color_Tab:				assembleColor(text, "tab-color-normal", value);			break;
	case Color_Tab_Hovered:		assembleColor(text, "tab-color-hovered", value);		break;
	case Color_Tab_Pressed:		assembleColor(text, "tab-color-pressed", value);		break;
	case Color_Tab_Checked:		assembleColor(text, "tab-color-checked", value);		break;
	case Color_Tab_Disable:		assembleColor(text, "tab-color-disable", value);		break;

	case Color_Header:			assembleColor(text, "header-color-normal", value);		break;
	case Color_Header_Hovered:	assembleColor(text, "header-color-hovered", value);		break;
	case Color_Header_Pressed:	assembleColor(text, "header-color-pressed", value);		break;
	case Color_Header_Checked:	assembleColor(text, "header-color-checked", value);		break;
	case Color_Header_Disable:	assembleColor(text, "header-color-disable", value);		break;

	case Color_Item:			assembleColor(text, "item-color-normal", value);		break;
	case Color_Item_Hovered:	assembleColor(text, "item-color-hovered", value);		break;
	case Color_Item_Pressed:	assembleColor(text, "item-color-pressed", value);		break;
	case Color_Item_Checked:	assembleColor(text, "item-color-checked", value);		break;
	case Color_Item_Disable:	assembleColor(text, "item-color-disable", value);		break;

	case Color_Prefix:			assembleColor(text, "prefix-color-normal", value);		break;
	case Color_Prefix_Hovered:	assembleColor(text, "prefix-color-hovered", value);		break;
	case Color_Prefix_Pressed:	assembleColor(text, "prefix-color-pressed", value);		break;
	case Color_Prefix_Disable:	assembleColor(text, "prefix-color-disable", value);		break;

	case Color_Suffix:			assembleColor(text, "suffix-color-normal", value);		break;
	case Color_Suffix_Hovered:	assembleColor(text, "suffix-color-hovered", value);		break;
	case Color_Suffix_Pressed:	assembleColor(text, "suffix-color-pressed", value);		break;
	case Color_Suffix_Disable:	assembleColor(text, "suffix-color-disable", value);		break;

	case Color_Wire:			assembleColor(text, "wire-color", value);		break;;
	case Color_Chunk:			assembleColor(text, "chunk-color", value);		break;
	case Color_Groove:			assembleColor(text, "groove-color", value);		break;
	case Color_Separator:		assembleColor(text, "separator-color", value);	break;
	case Color_Indicator:		assembleColor(text, "indicator-color", value);	break;
	case Color_Grid_Ver:		assembleColor(text, "grid-ver-color", value);	break;
	case Color_Grid_Hor:		assembleColor(text, "grid-hor-color", value);	break;

	case Image_Title:			assembleImage(text, "title-image-normal", value);	break;
	case Image_Title_Hovered:	assembleImage(text, "title-image-hovered", value);	break;
	case Image_Title_Pressed:	assembleImage(text, "title-image-pressed", value);	break;
	case Image_Title_Checked:	assembleImage(text, "title-image-checked", value);	break;
	case Image_Title_Disable:	assembleImage(text, "title-image-disable", value);	break;

	case Image_Background:			assembleImage(text, "background-image-normal", value);	break;
	case Image_Background_Hovered:	assembleImage(text, "background-image-hovered", value);	break;
	case Image_Background_Pressed:	assembleImage(text, "background-image-pressed", value);	break;
	case Image_Background_Checked:	assembleImage(text, "background-image-checked", value);	break;
	case Image_Background_Disable:	assembleImage(text, "background-image-disable", value);	break;

	case Image_Header:			assembleImage(text, "header-image-normal", value);	break;
	case Image_Header_Hovered:	assembleImage(text, "header-image-hovered", value);	break;
	case Image_Header_Pressed:	assembleImage(text, "header-image-pressed", value);	break;
	case Image_Header_Checked:	assembleImage(text, "header-image-checked", value);	break;
	case Image_Header_Disable:	assembleImage(text, "header-image-disable", value);	break;

	case Image_Item:			assembleImage(text, "item-image-normal", value);	break;
	case Image_Item_Hovered:	assembleImage(text, "item-image-hovered", value);	break;
	case Image_Item_Pressed:	assembleImage(text, "item-image-pressed", value);	break;
	case Image_Item_Checked:	assembleImage(text, "item-image-checked", value);	break;
	case Image_Item_Disable:	assembleImage(text, "item-image-disable", value);	break;

	case Image_Separator:	assembleImage(text, "separator-image", value);	break;
	case Image_Groove:		assembleImage(text, "groove-image", value);		break;

	case Icon_Arrow_Up:		assembleImage(text, "arrow-icon-up", value);	break;
	case Icon_Arrow_Down:	assembleImage(text, "arrow-icon-down", value);	break;
	case Icon_Arrow_Left:	assembleImage(text, "arrow-icon-left", value);	break;
	case Icon_Arrow_Right:	assembleImage(text, "arrow-icon-right", value);	break;

	case Icon_Title:		assembleImage(text, "title-icon", value);		break;
	case Icon_Expand:		assembleImage(text, "expand-icon", value);		break;
	case Icon_Shrink:		assembleImage(text, "shrink-icon", value);		break;
	case Icon_About:		assembleImage(text, "about-icon", value);		break;
	case Icon_Information:	assembleImage(text, "information-icon", value);	break;
	case Icon_Question:		assembleImage(text, "question-icon", value);	break;
	case Icon_Warning:		assembleImage(text, "warning-icon", value);		break;
	case Icon_Critical:		assembleImage(text, "critical-icon", value);	break;
	default:
		int aaaa = srole;
		int a = 0;
		break;
	}
}
